/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package black.market.main;

// Need the following import to get access to the app resources, since this
// class is in a sub-package.
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import javax.xml.xpath.XPathExpressionException;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class Spinner1 extends Activity {
	private Spinner spinner1 = null;
	private ArrayAdapter<String> spinner1Adapter = null;
	private ArrayList<String[]> spinner1ArrayList = null;

	void showToast(CharSequence msg) {
		Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.spinner_1);

		// Spinner s1 = (Spinner) findViewById(R.id.spinner1);
		// // ArrayAdapter<CharSequence> adapter =
		// ArrayAdapter.createFromResource(this, R.array.colors,
		// android.R.layout.simple_spinner_item);
		// adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		// s1.setAdapter(adapter);
		// s1.setOnItemSelectedListener(new OnItemSelectedListener() {
		// public void onItemSelected(AdapterView<?> parent, View view, int
		// position, long id) {
		// showToast("Spinner1: position=" + position + " id=" + id);
		// }
		//
		// public void onNothingSelected(AdapterView<?> parent) {
		// showToast("Spinner1: unselected");
		// }
		// });
	}

	public void createWeatherSpinner() {
		spinner1 = (Spinner) findViewById(R.id.spinner1);
		spinner1Adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_item);
	}

	public String openKmaDataXml() throws IOException {
		InputStream is = getResources().openRawResource(R.raw.kmadata);
		byte[] tmpByteArr = new byte[is.available()];
		int pos = 0;
		int size = 10;
		int tmp = 0;
		while ((size = is.read(tmpByteArr, pos, size)) > 0) {
			pos += size;
			tmp = tmpByteArr.length - pos;
			if (tmp < 10) {
				size = tmp;
			}
		}
		is.close();
		return new String(tmpByteArr, "utf-8");
	}

	public void getVillageData(String reqExpression) throws XPathExpressionException, IOException {
		XpathParser parser = new XpathParser();
		spinner1ArrayList = new ArrayList<String[]>();
		parser.gridXpathParserCompile(openKmaDataXml(), reqExpression);

	}
}
